#!/usr/bin/env php
<?php
$SOAR_DIR=getenv("SOAR_DIR");
if(empty($SOAR_DIR)) $SOAR_DIR="/opt/soar";
$SOAR_DIR="../../../../../..";
include "$SOAR_DIR/common/php/soar/soar.inc";

function usage($selfname)
{/*{{{*/
    print "Usage: $selfname host:port service [ para... ]\n";
}/*}}}*/

function main($argv)
{/*{{{*/
    if(count($argv) < 3)
    {
        usage(basename($argv[0]));
        return 1;
    }

    $sn=new svcnode($argv[1], svcnode::ONESHOT);
    $request="";
    for($i=3; $i<count($argv); ++$i)
    {
        para::put_item($request, $argv[$i]);
    }
    print "Request:\n".$argv[2]." ".$request."\n";
    print "----------------------------------------\n";
    $respond=$sn->call($argv[2], $request);
    if($respond === false)
    {
        print "svcnode call fail\n";
        return 1;
    }
    print "Respond:\n";
    $curr=0;
    while(!is_null($item=para::get_item($respond, $curr)))
    {
        print $item."\n";
    }
    print "----------------------------------------\n";

    return 0;
}/*}}}*/

exit(main($argv));
?>
